package com.teacherprofile.manage.controller;

import java.util.List;

import com.teacherprofile.common.annotation.Log;
import com.teacherprofile.common.core.controller.BaseController;
import com.teacherprofile.common.core.domain.AjaxResult;
import com.teacherprofile.common.core.page.TableDataInfo;
import com.teacherprofile.common.domain.TechnicalServices;
import com.teacherprofile.common.enums.BusinessType;
import com.teacherprofile.common.utils.StringUtils;
import com.teacherprofile.common.utils.poi.ExcelUtil;
import com.teacherprofile.manage.domain.dto.TechnicalServicesExportDTO;
import jakarta.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.teacherprofile.manage.service.ITechnicalServicesService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 课题项目Controller
 *
 * @author qvtu
 * @date 2025-05-16
 */
@Api(tags = "课题项目")
@RestController
@RequestMapping("/manage/services")
public class TechnicalServicesController extends BaseController {
    @Autowired
    private ITechnicalServicesService technicalServicesService;

    /**
     * 查询课题项目列表
     */
    @ApiOperation(value = "查询课题项目列表")
    @PreAuthorize("@ss.hasPermi('manage:services:list')")
    @GetMapping("/list")
    public TableDataInfo list(TechnicalServices technicalServices) {
        startPage();
        List<TechnicalServices> list = technicalServicesService.selectTechnicalServicesList(technicalServices);
        return getDataTable(list);
    }

    /**
     * 导出课题项目列表
     */
    @ApiOperation(value = "导出课题项目列表")
    @PreAuthorize("@ss.hasPermi('manage:services:export')")
    @Log(title = "课题项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TechnicalServicesExportDTO technicalServicesExportDTO) {
        List<TechnicalServices> list = technicalServicesService.selectTechnicalServicesList(technicalServicesExportDTO);
        ExcelUtil<TechnicalServices> util = new ExcelUtil<TechnicalServices>(TechnicalServices.class);
        util.exportEasyExcel(response, list, "课题项目数据", StringUtils.str2List(technicalServicesExportDTO.getExportFields(), ",", true, true));
    }

    /**
     * 获取课题项目详细信息
     */
    @ApiOperation(value = "获取课题项目详细信息")
    @PreAuthorize("@ss.hasPermi('manage:services:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        TechnicalServices technicalServices = technicalServicesService.selectTechnicalServicesById(id);
//        System.out.println(technicalServices);
        return success(technicalServices);
    }

    /**
     * 新增课题项目
     */
    @ApiOperation(value = "新增课题项目")
    @PreAuthorize("@ss.hasPermi('manage:services:add')")
    @Log(title = "课题项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TechnicalServices technicalServices) {
        return toAjax(technicalServicesService.insertTechnicalServices(technicalServices));
    }

    /**
     * 修改课题项目
     */
    @ApiOperation(value = "修改课题项目")
    @PreAuthorize("@ss.hasPermi('manage:services:edit')")
    @Log(title = "课题项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TechnicalServices technicalServices) {
        return toAjax(technicalServicesService.updateTechnicalServices(technicalServices));
    }

    /**
     * 删除课题项目
     */
    @ApiOperation("删除课题项目")
    @PreAuthorize("@ss.hasPermi('manage:services:remove')")
    @Log(title = "课题项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(technicalServicesService.deleteTechnicalServicesByIds(ids));
    }

    /**
     * 导入课题项目数据
     *
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation("导入课题项目")
    @Log(title = "导入管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<TechnicalServices> util = new ExcelUtil<TechnicalServices>(TechnicalServices.class);
        List<TechnicalServices> technicalServicesList = util.importEasyExcel(file.getInputStream());
        String message = technicalServicesService.importData(technicalServicesList);
//        System.out.println("导入课题项目");
        System.out.println(message);
        return success(message);
    }

    /**
     * 审批
     */
    @ApiOperation(value = "课题项目数据审批")
    @PreAuthorize("@ss.hasPermi('manage:copyright:check')")
    @Log(title = "课题项目数据管理", businessType = BusinessType.UPDATE)
    @PutMapping("/check")
    public AjaxResult check(@RequestBody TechnicalServices technicalServices) {
        return toAjax(technicalServicesService.check(technicalServices));
    }

}
